Fix double-free crash under Perl ithreads#198
Draft
toddr-bot wants to merge 1 commit into
Draft
Conversation
When Perl ithreads clone an interpreter, blessed IV references (like our rsaData* pointers) are copied as raw integers. Both parent and child threads then call DESTROY on the same EVP_PKEY, causing a double-free. CLONE_SKIP makes cloned objects undef in child threads instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
CLONE_SKIPto prevent Crypt::OpenSSL::RSA objects from causingdouble-free crashes when Perl ithreads clone the interpreter.
Why
When
threads->create()clones the interpreter, blessed IV referencesare copied as raw integer values. Both parent and child threads end up
with the same
rsaData*pointer. When each thread'sDESTROYfires,the same
EVP_PKEYis freed twice — segfault or heap corruption.This is the standard failure mode for XS modules holding C pointers
under ithreads. The static buffer fix in PR #136 addressed one aspect
of thread safety, but the object lifecycle issue remained.
How
CLONE_SKIP { 1 }tells Perl to undef objects of this class in childthreads rather than shallow-copying them. Child threads must create
their own key objects — a safer semantic than silent memory corruption.
Testing
t/threads.tverifiesCLONE_SKIPis defined and that childthreads can independently generate keys without affecting the parent.
🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 52 insertions(+)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline